package com.twu.biblioteca;

import java.util.List;

public class BibliotecaBookReservations implements BibliotecaCommand {

    private BibliotecaApp bibliotecaApp;

    public BibliotecaBookReservations(BibliotecaApp libraryBooks) {
        bibliotecaApp = libraryBooks;
    }


    @Override
    public void execute() {

        String errorMessage = "Sorry we don't have that book yet.";
        String successMessage = "Thank You! Enjoy the book.";

        String option = bibliotecaApp.getInput();
        List<LibraryBook> bookList = bibliotecaApp.getBookList();


        LibraryBook desiredBook = null;


        for (LibraryBook book : bookList){
            if(option.equals(book.getBookTitle())){
               desiredBook = book;
            }
        }

        if (desiredBook.isReserved()) {
            bibliotecaApp.outputMessage(errorMessage);
        } else {
            desiredBook.reserve();
            bibliotecaApp.outputMessage(successMessage);
        }
    }
}
